/**
 *  Copyright (C) 2013  Piotr Szczepański
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package main;

import edu.pw.elka.gtsna.community_detection.CommunityStructure;
import edu.pw.elka.gtsna.community_detection.HierarchicalCommunityDetection;
import edu.pw.elka.gtsna.graph.UndirectedGraph;
import edu.pw.elka.gtsna.graph_creator.GMLReader;
import edu.pw.elka.gtsna.graph_creator.TGFReader;
import edu.pw.elka.gtsna.graph_evaluators.Coverage;
import edu.pw.elka.gtsna.graph_evaluators.Modularity;
import edu.pw.elka.gtsna.interaction_index.InteractionIndex;
import edu.pw.elka.gtsna.interaction_index.NaiveII;
import edu.pw.elka.gtsna.interaction_index.kStepsDegreeII;

/**
 * @author Piotr Lech Szczepański
 * @author P.Szczepanski@ii.pw.edu.pl 
 *
 */
public class Main3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length < 2) {
			System.out.println("usage: ./program <datasetPath> <steps> <KSTEPS|NAIVE> <COMPLETE|SET|...>");
			return;
		}
		
		String dataset = args[0];
		int stepsNumber = Integer.parseInt(args[1]);
		
		UndirectedGraph graph;
		if (dataset.endsWith(".tgf")) {
			graph = new UndirectedGraph(new TGFReader(dataset));
		} else {
			graph = new UndirectedGraph(new GMLReader(dataset));
		}

		InteractionIndex ii;
		if (args.length > 2 && args[2].equals("NAIVE")) {
			ii = new NaiveII(graph,stepsNumber);
		} else {
			ii = new kStepsDegreeII(graph,stepsNumber);
		}
		
		System.out.println("II is: "+ii.getClass()+" k: "+stepsNumber);
		System.out.println("II precomputing...");
		ii.preComputation();
		System.out.println("precomputed");
		
		HierarchicalCommunityDetection cd = new HierarchicalCommunityDetection(graph ,ii);
		CommunityStructure csg = cd.detectCommunities();
		
		Modularity mod = new Modularity(graph, csg);
		Coverage cov = new Coverage(graph, csg);
		System.out.println("***********");
		System.out.println(csg);
		
		
		
		System.out.println(mod.evaluate());
		System.out.println(cov.evaluate());
	//	csg.printRFormat(graph);
	}

}
